<?php
	

	session_start();	
	if(!$_SESSION['login_user']){
		header("location: ../pages/login.php");
	}
	if(!$_SESSION['admin']){
		header("location: ../pages/login.php?error="+urlencode("Accesso riservato agli amministratori"));
	}
	
	include_once '../appcontroller.php';
	
	$slide = $_GET["slide"];
	if (!$slide) {
		$slide = 1;
	}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Type" content="text/html;" />
		<meta name="viewport" content="width=device-width, initial-scale=1"/>
			
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
		<link rel="stylesheet" href="../css/jquery.mobile.pagination.css"></link>
		<link href="../css/style.css" rel="stylesheet" type="text/css" ></link>
		
		<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
		<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.js"></script>
		
		
		<script src="../lib/jquery.mobile.pagination.js"></script>
		<script src="../lib/pathways.js"></script>
		<script src="../lib/cruscotto.js"></script>
		<title>Pannello di controllo</title>
	
	</head>

	<body>
	
		<div id="container">
			
			<div data-role="header" data-theme="c">
			  <h1>Pannello di controllo</h1>
			  <a onclick="logout();" data-icon="arrow-l" class="ui-btn-left">Esci</a>
			  <a onclick="openCasoClinico(<?php echo $slide?>);" data-icon="gear" data-iconpos="right" class="ui-btn-right">Caso clinico</a>
			</div>
			
			<center>
				<b style="color: red;" id="error"><?php echo $error ; ?></b>
			</center>
			
			<div id="main" data-role="content">
				
				<iframe src="statistiche.php" width="100%" height="410px" >
				  Grafico statistiche Pathways in NET
				</iframe>
				
				<table cellpadding="5px" width="98%">
					<tr>
						<td>
							<div data-role="collapsible" id="box_nota" >
							    <h4>Note degli utenti</h4>
		    					
		    					<ul data-role="listview" data-split-icon="plus" data-theme="c" data-split-theme="c" >
		    					
		    					<?php 
			    					global $api;
			    					$risposta = new risposta($api->pdo);
									$res = $risposta->listNote();
									
									$result = array();
									
									foreach ($res as $r){
										echo '<li>';
										echo 	'<a href="#">';
										echo 		'Slide '.$r["num_slide"].' - '.$r["nome"].' '.$r["cognome"].' - '.$r["struttura"];
										echo 	'</a>';
										echo 	'<a href="#popupNota'.$r["id_risp"].'" data-rel="popup" data-position-to="body" data-transition="pop">';
										echo 		'Visualizza nota';
										echo 	'</a>';
										
										echo 	'<div data-role="popup" id="popupNota'.$r["id_risp"].'" data-theme="c" 
										    		data-overlay-theme="b" class="ui-content ui-popup ui-body-d ui-overlay-shadow ui-corner-all" 
										    			style="max-width:340px; padding-bottom:2em;">';
										echo 		'<h3>'.$r["nome"].' '.$r["cognome"].'</h3>';
										echo 		'<b>'.$r["struttura"].'</b>';
										echo 		'<p>'.$r["nota"].'</p>';
										echo 	'</div>';
										echo '</li>';
									}
								
		    					?>
								    
								</ul>
								
							</div>
						</td>
					</tr>
				</table>
				
				<table cellpadding="5px" width="98%">
					<tr>
						<td>
							<div data-role="collapsible" id="box_nota" >
							    <h4>Anagrafica utenti</h4>
		    					
		    					<ul data-role="listview" data-split-icon="plus" data-theme="c" data-split-theme="c" >
								    <?php 
								    	global $api;
								    	$usr = new user($api->pdo);
		
										$users = array();
										$utenti= $usr->listUser();
										foreach ($utenti as $u){
											//array_push($users, $u);
											echo '<li>';
											echo 	'<a href="#">';
											if ($u["admin"]) {
							    				echo '<img id="img_'.$u['id_str'].'" src="../img/user.png" title="Amministratore" class="ui-li-icon ui-corner-none" width="16"/>';
							    			}else {
							    				echo '<img id="img_'.$u['id_str'].'" src="" class="ui-li-icon ui-corner-none" width="16"/>';
							    			}
											echo 		$u["username"];
											echo 	'</a>';
											echo 	'<a href="#purchase" onclick="currentUser='.$u['id_str'].'" data-rel="popup" data-position-to="body" data-transition="pop">Amministratore?</a>';
											echo '</li>';
										}
										
										
								    ?>
								</ul>
							</div>
						</td>
					</tr>
				</table>
					
			</div>
			
			<div data-role="popup" id="purchase" data-theme="c" 
	    		data-overlay-theme="b" class="ui-content ui-popup ui-body-d ui-overlay-shadow ui-corner-all" 
	    			style="max-width:340px; padding-bottom:2em;">
				<h3>Impostare come amministratore?</h3>
				<p>L'utente potrà accedere al pannello di controllo.</p>
				
				<a onclick="setAmministratore(1);" data-role="button" data-rel="back" 
					data-theme="c" data-icon="check" data-inline="true" 
						data-mini="true" data-corners="true" data-shadow="true" 
							data-iconshadow="true" data-wrapperels="span" 
								class="ui-btn ui-btn-up-b ui-shadow ui-btn-corner-all ui-mini ui-btn-inline ui-btn-icon-left">
								<span class="ui-btn-inner"><span class="ui-btn-text">SI</span>
								<span class="ui-icon ui-icon-check ui-icon-shadow">&nbsp;</span></span></a>
				
				<a onclick="setAmministratore(0);" data-role="button" data-rel="back" 
					data-inline="true" data-mini="true" data-corners="true" 
						data-shadow="true" data-iconshadow="true" data-wrapperels="span" 
							data-theme="c" class="ui-btn ui-shadow ui-btn-corner-all ui-mini ui-btn-inline ui-btn-up-c ui-btn-active">
					<span class="ui-btn-inner">
						<span class="ui-btn-text">NO</span>
					</span>
				</a>
			</div>
			
			
			
		</div>
	</body>

</html>